/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MainWindow.java
 *
 * Created on 08/09/2010, 15:20:34
 */

package Interface;

import javax.swing.ImageIcon;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import main.Main;
import main.ParametersConfig;
import main.ParametersSerial;

/**
 *
 * @author victor
 */
public class MainWindow extends javax.swing.JFrame {

    /** Creates new form MainWindow */
    public MainWindow() {
        initComponents();
        program = new Main();
        programConfig = program.getConfig();
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jDesktopPane = new javax.swing.JDesktopPane();
        jInternalFrameStatus = new javax.swing.JInternalFrame();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextAreaLog = new javax.swing.JTextArea();
        jLabelTime = new javax.swing.JLabel();
        jLabelCyclesStatus = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabelReport = new javax.swing.JLabel();
        jTextFieldTime = new javax.swing.JTextField();
        jTextFieldCycles = new javax.swing.JTextField();
        jTextFieldLength = new javax.swing.JTextField();
        jInternalFrameConfig = new javax.swing.JInternalFrame();
        jLabelStepperSpeed = new javax.swing.JLabel();
        jSpinnerStepperSpeed = new javax.swing.JSpinner();
        jLabelWireStep = new javax.swing.JLabel();
        jSpinnerWireStep = new javax.swing.JSpinner();
        jLabelStrain = new javax.swing.JLabel();
        jSpinnerStraining = new javax.swing.JSpinner();
        jLabelcycles = new javax.swing.JLabel();
        jSpinnerCycles = new javax.swing.JSpinner();
        jInternalFrameDebug = new javax.swing.JInternalFrame();
        jButtonSend = new javax.swing.JButton();
        jTextFieldCommand = new javax.swing.JTextField();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextAreaDebug = new javax.swing.JTextArea();
        jLabelTimeout = new javax.swing.JLabel();
        jSpinnerTimeout = new javax.swing.JSpinner();
        jLabelCommand = new javax.swing.JLabel();
        jPanelToolBar = new javax.swing.JPanel();
        jToolBarOperation = new javax.swing.JToolBar();
        jButtonStart = new javax.swing.JButton();
        jButtonRestart = new javax.swing.JButton();
        jToolBarDevice = new javax.swing.JToolBar();
        jButtonConnect = new javax.swing.JButton();
        jButtonConfigSerial = new javax.swing.JButton();
        jButtonDebug = new javax.swing.JButton();
        jButtonConfigDebug = new javax.swing.JButton();
        jMenuBar = new javax.swing.JMenuBar();
        jMenuFile = new javax.swing.JMenu();
        jMenuItemExit = new javax.swing.JMenuItem();
        jMenuView = new javax.swing.JMenu();
        jCheckBoxMenuItemOperation = new javax.swing.JCheckBoxMenuItem();
        jCheckBoxMenuItemStatus = new javax.swing.JCheckBoxMenuItem();
        jCheckBoxMenuItemDebug = new javax.swing.JCheckBoxMenuItem();
        jMenuToolBars = new javax.swing.JMenu();
        jCheckBoxMenuItemOperationToolBar = new javax.swing.JCheckBoxMenuItem();
        jCheckBoxMenuItemDeviceTool = new javax.swing.JCheckBoxMenuItem();
        jMenuOperation = new javax.swing.JMenu();
        jMenuItemStart = new javax.swing.JMenuItem();
        jMenuItemPause = new javax.swing.JMenuItem();
        jMenuItemRestart = new javax.swing.JMenuItem();
        jMenuDevice = new javax.swing.JMenu();
        jMenuItemConnect = new javax.swing.JMenuItem();
        jMenuItemConnectDebug = new javax.swing.JMenuItem();
        jMenuConfiguration = new javax.swing.JMenu();
        jMenuItemOptions = new javax.swing.JMenuItem();
        jMenuItemSerialDeviceConfiguration = new javax.swing.JMenuItem();
        jMenuItemSerialDebugConfiguration = new javax.swing.JMenuItem();
        jMenuHelp = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Traktana - Centro Brasileiro de Pesquisas Físicas");
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        jDesktopPane.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jDesktopPane.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jDesktopPane.setDoubleBuffered(true);
        jDesktopPane.setSelectedFrame(jInternalFrameStatus);

        jInternalFrameStatus.setClosable(true);
        jInternalFrameStatus.setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
        jInternalFrameStatus.setIconifiable(true);
        jInternalFrameStatus.setResizable(true);
        jInternalFrameStatus.setTitle("Status");
        jInternalFrameStatus.setFrameIcon(new javax.swing.ImageIcon(getClass().getResource("/Interface/icons/chart_curve.png"))); // NOI18N
        jInternalFrameStatus.setVisible(true);
        jInternalFrameStatus.addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
                jInternalFrameStatusInternalFrameClosing(evt);
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
            }
        });

        jTextAreaLog.setColumns(20);
        jTextAreaLog.setRows(5);
        jTextAreaLog.setText("\n LogProcess");
        jScrollPane1.setViewportView(jTextAreaLog);

        jLabelTime.setText("Time:");

        jLabelCyclesStatus.setText("Cycles:");

        jLabel1.setText("Length plain:");

        jLabelReport.setText("Report:");

        jTextFieldTime.setEditable(false);
        jTextFieldTime.setEnabled(false);

        jTextFieldCycles.setEditable(false);
        jTextFieldCycles.setEnabled(false);

        jTextFieldLength.setEditable(false);
        jTextFieldLength.setEnabled(false);

        javax.swing.GroupLayout jInternalFrameStatusLayout = new javax.swing.GroupLayout(jInternalFrameStatus.getContentPane());
        jInternalFrameStatus.getContentPane().setLayout(jInternalFrameStatusLayout);
        jInternalFrameStatusLayout.setHorizontalGroup(
            jInternalFrameStatusLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jInternalFrameStatusLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jInternalFrameStatusLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jInternalFrameStatusLayout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jInternalFrameStatusLayout.createSequentialGroup()
                        .addGroup(jInternalFrameStatusLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabelTime)
                            .addComponent(jLabelCyclesStatus))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addGroup(jInternalFrameStatusLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jTextFieldLength)
                    .addComponent(jTextFieldTime, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE)
                    .addComponent(jTextFieldCycles))
                .addContainerGap(92, Short.MAX_VALUE))
            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 309, Short.MAX_VALUE)
            .addGroup(jInternalFrameStatusLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelReport)
                .addContainerGap(251, Short.MAX_VALUE))
        );
        jInternalFrameStatusLayout.setVerticalGroup(
            jInternalFrameStatusLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jInternalFrameStatusLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jInternalFrameStatusLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldTime, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelTime))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jInternalFrameStatusLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelCyclesStatus)
                    .addComponent(jTextFieldCycles, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jInternalFrameStatusLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldLength, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addGap(28, 28, 28)
                .addComponent(jLabelReport)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 215, Short.MAX_VALUE))
        );

        jInternalFrameStatus.setBounds(0, 0, 320, 400);
        jDesktopPane.add(jInternalFrameStatus, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jInternalFrameConfig.setClosable(true);
        jInternalFrameConfig.setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
        jInternalFrameConfig.setIconifiable(true);
        jInternalFrameConfig.setResizable(true);
        jInternalFrameConfig.setTitle("Operation");
        jInternalFrameConfig.setFrameIcon(new javax.swing.ImageIcon(getClass().getResource("/Interface/icons/database_gear.png"))); // NOI18N
        jInternalFrameConfig.setVisible(true);
        jInternalFrameConfig.addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
                jInternalFrameConfigInternalFrameClosing(evt);
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
            }
        });

        jLabelStepperSpeed.setText("Stepper Speed:");

        jLabelWireStep.setText("Wire step:");

        jLabelStrain.setText("Straining:");

        jLabelcycles.setText("Cycles:");

        javax.swing.GroupLayout jInternalFrameConfigLayout = new javax.swing.GroupLayout(jInternalFrameConfig.getContentPane());
        jInternalFrameConfig.getContentPane().setLayout(jInternalFrameConfigLayout);
        jInternalFrameConfigLayout.setHorizontalGroup(
            jInternalFrameConfigLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jInternalFrameConfigLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jInternalFrameConfigLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabelWireStep)
                    .addComponent(jLabelStepperSpeed)
                    .addComponent(jLabelStrain)
                    .addComponent(jLabelcycles))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jInternalFrameConfigLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jSpinnerStepperSpeed, javax.swing.GroupLayout.DEFAULT_SIZE, 95, Short.MAX_VALUE)
                    .addComponent(jSpinnerWireStep)
                    .addComponent(jSpinnerStraining)
                    .addComponent(jSpinnerCycles))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jInternalFrameConfigLayout.setVerticalGroup(
            jInternalFrameConfigLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jInternalFrameConfigLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jInternalFrameConfigLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jSpinnerStepperSpeed, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelStepperSpeed))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jInternalFrameConfigLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelWireStep)
                    .addComponent(jSpinnerWireStep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jInternalFrameConfigLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jSpinnerStraining, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelStrain))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jInternalFrameConfigLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jSpinnerCycles, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelcycles))
                .addContainerGap(33, Short.MAX_VALUE))
        );

        jInternalFrameConfig.setBounds(330, 0, 240, 204);
        jDesktopPane.add(jInternalFrameConfig, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jInternalFrameDebug.setClosable(true);
        jInternalFrameDebug.setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
        jInternalFrameDebug.setIconifiable(true);
        jInternalFrameDebug.setTitle("Debug");
        jInternalFrameDebug.setFrameIcon(new javax.swing.ImageIcon(getClass().getResource("/Interface/icons/bug.png"))); // NOI18N
        jInternalFrameDebug.setVisible(true);
        jInternalFrameDebug.addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
                jInternalFrameDebugInternalFrameClosing(evt);
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
            }
        });

        jButtonSend.setText("Send");

        jTextAreaDebug.setColumns(20);
        jTextAreaDebug.setLineWrap(true);
        jTextAreaDebug.setRows(5);
        jScrollPane2.setViewportView(jTextAreaDebug);

        jLabelTimeout.setText("Timeout (s):");

        jSpinnerTimeout.setModel(new javax.swing.SpinnerNumberModel(Float.valueOf(1.0f), Float.valueOf(0.0f), Float.valueOf(20.0f), Float.valueOf(1.0f)));

        jLabelCommand.setText("Command:");

        javax.swing.GroupLayout jInternalFrameDebugLayout = new javax.swing.GroupLayout(jInternalFrameDebug.getContentPane());
        jInternalFrameDebug.getContentPane().setLayout(jInternalFrameDebugLayout);
        jInternalFrameDebugLayout.setHorizontalGroup(
            jInternalFrameDebugLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jInternalFrameDebugLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jInternalFrameDebugLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 205, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jInternalFrameDebugLayout.createSequentialGroup()
                        .addGroup(jInternalFrameDebugLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabelCommand)
                            .addComponent(jLabelTimeout))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jInternalFrameDebugLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jInternalFrameDebugLayout.createSequentialGroup()
                                .addComponent(jSpinnerTimeout, javax.swing.GroupLayout.DEFAULT_SIZE, 65, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButtonSend))
                            .addComponent(jTextFieldCommand, javax.swing.GroupLayout.DEFAULT_SIZE, 116, Short.MAX_VALUE))))
                .addContainerGap())
        );
        jInternalFrameDebugLayout.setVerticalGroup(
            jInternalFrameDebugLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jInternalFrameDebugLayout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(jInternalFrameDebugLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldCommand, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelCommand))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jInternalFrameDebugLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jButtonSend, javax.swing.GroupLayout.PREFERRED_SIZE, 28, Short.MAX_VALUE)
                    .addGroup(jInternalFrameDebugLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jSpinnerTimeout)
                        .addComponent(jLabelTimeout)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(24, 24, 24))
        );

        jInternalFrameDebug.setBounds(580, 0, 240, 340);
        jDesktopPane.add(jInternalFrameDebug, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jPanelToolBar.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jToolBarOperation.setFloatable(false);

        jButtonStart.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Interface/icons/play.png"))); // NOI18N
        jButtonStart.setToolTipText("Start/Pause the process.");
        jButtonStart.setFocusable(false);
        jButtonStart.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButtonStart.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButtonStart.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonStartActionPerformed(evt);
            }
        });
        jToolBarOperation.add(jButtonStart);

        jButtonRestart.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Interface/icons/refresh_32.png"))); // NOI18N
        jButtonRestart.setToolTipText("Restart the process.");
        jButtonRestart.setFocusable(false);
        jButtonRestart.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButtonRestart.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBarOperation.add(jButtonRestart);

        jToolBarDevice.setFloatable(false);
        jToolBarDevice.setRollover(true);

        jButtonConnect.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Interface/icons/connect.png"))); // NOI18N
        jButtonConnect.setToolTipText("Connect device");
        jButtonConnect.setFocusable(false);
        jButtonConnect.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButtonConnect.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButtonConnect.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonConnectActionPerformed(evt);
            }
        });
        jToolBarDevice.add(jButtonConnect);

        jButtonConfigSerial.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Interface/icons/cog.png"))); // NOI18N
        jButtonConfigSerial.setToolTipText("Serial device configuration");
        jButtonConfigSerial.setFocusable(false);
        jButtonConfigSerial.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButtonConfigSerial.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButtonConfigSerial.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemSerialDeviceConfigurationActionPerformed(evt);
            }
        });
        jToolBarDevice.add(jButtonConfigSerial);

        jButtonDebug.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Interface/icons/connectbug.png"))); // NOI18N
        jButtonDebug.setToolTipText("Connect serial debug");
        jButtonDebug.setFocusable(false);
        jButtonDebug.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButtonDebug.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButtonDebug.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonDebugActionPerformed(evt);
            }
        });
        jToolBarDevice.add(jButtonDebug);

        jButtonConfigDebug.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Interface/icons/cogbug.png"))); // NOI18N
        jButtonConfigDebug.setToolTipText("Serial debug configuration");
        jButtonConfigDebug.setFocusable(false);
        jButtonConfigDebug.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButtonConfigDebug.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButtonConfigDebug.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemSerialDebugConfigurationActionPerformed(evt);
            }
        });
        jToolBarDevice.add(jButtonConfigDebug);

        javax.swing.GroupLayout jPanelToolBarLayout = new javax.swing.GroupLayout(jPanelToolBar);
        jPanelToolBar.setLayout(jPanelToolBarLayout);
        jPanelToolBarLayout.setHorizontalGroup(
            jPanelToolBarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelToolBarLayout.createSequentialGroup()
                .addComponent(jToolBarOperation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jToolBarDevice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(550, Short.MAX_VALUE))
        );
        jPanelToolBarLayout.setVerticalGroup(
            jPanelToolBarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBarOperation, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jToolBarDevice, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        jMenuFile.setText("File");

        jMenuItemExit.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, java.awt.event.InputEvent.ALT_MASK));
        jMenuItemExit.setText("Exit");
        jMenuItemExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemExitActionPerformed(evt);
            }
        });
        jMenuFile.add(jMenuItemExit);

        jMenuBar.add(jMenuFile);

        jMenuView.setText("View");

        jCheckBoxMenuItemOperation.setSelected(true);
        jCheckBoxMenuItemOperation.setText("Operation");
        jCheckBoxMenuItemOperation.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxMenuItemOperationActionPerformed(evt);
            }
        });
        jMenuView.add(jCheckBoxMenuItemOperation);

        jCheckBoxMenuItemStatus.setSelected(true);
        jCheckBoxMenuItemStatus.setText("Status");
        jCheckBoxMenuItemStatus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxMenuItemStatusActionPerformed(evt);
            }
        });
        jMenuView.add(jCheckBoxMenuItemStatus);

        jCheckBoxMenuItemDebug.setSelected(true);
        jCheckBoxMenuItemDebug.setText("Debug");
        jCheckBoxMenuItemDebug.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxMenuItemDebugActionPerformed(evt);
            }
        });
        jMenuView.add(jCheckBoxMenuItemDebug);

        jMenuToolBars.setText("ToolBars");

        jCheckBoxMenuItemOperationToolBar.setSelected(true);
        jCheckBoxMenuItemOperationToolBar.setText("Operation");
        jCheckBoxMenuItemOperationToolBar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxMenuItemOperationToolBarActionPerformed(evt);
            }
        });
        jMenuToolBars.add(jCheckBoxMenuItemOperationToolBar);

        jCheckBoxMenuItemDeviceTool.setSelected(true);
        jCheckBoxMenuItemDeviceTool.setText("Device/Configuration");
        jCheckBoxMenuItemDeviceTool.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxMenuItemDeviceToolActionPerformed(evt);
            }
        });
        jMenuToolBars.add(jCheckBoxMenuItemDeviceTool);

        jMenuView.add(jMenuToolBars);

        jMenuBar.add(jMenuView);

        jMenuOperation.setText("Operation");

        jMenuItemStart.setText("Start");
        jMenuOperation.add(jMenuItemStart);

        jMenuItemPause.setText("Pause");
        jMenuItemPause.setEnabled(false);
        jMenuOperation.add(jMenuItemPause);

        jMenuItemRestart.setText("Restart");
        jMenuOperation.add(jMenuItemRestart);

        jMenuBar.add(jMenuOperation);

        jMenuDevice.setText("Device");

        jMenuItemConnect.setText("Connect");
        jMenuDevice.add(jMenuItemConnect);

        jMenuItemConnectDebug.setText("Connect Debug");
        jMenuDevice.add(jMenuItemConnectDebug);

        jMenuBar.add(jMenuDevice);

        jMenuConfiguration.setText("Configuration");

        jMenuItemOptions.setText("Options");
        jMenuConfiguration.add(jMenuItemOptions);

        jMenuItemSerialDeviceConfiguration.setText("Serial Device");
        jMenuItemSerialDeviceConfiguration.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemSerialDeviceConfigurationActionPerformed(evt);
            }
        });
        jMenuConfiguration.add(jMenuItemSerialDeviceConfiguration);

        jMenuItemSerialDebugConfiguration.setText("Serial Debug");
        jMenuItemSerialDebugConfiguration.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemSerialDebugConfigurationActionPerformed(evt);
            }
        });
        jMenuConfiguration.add(jMenuItemSerialDebugConfiguration);

        jMenuBar.add(jMenuConfiguration);

        jMenuHelp.setText("Help");
        jMenuBar.add(jMenuHelp);

        setJMenuBar(jMenuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanelToolBar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jDesktopPane, javax.swing.GroupLayout.DEFAULT_SIZE, 828, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanelToolBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jDesktopPane, javax.swing.GroupLayout.PREFERRED_SIZE, 453, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jMenuItemExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemExitActionPerformed
        // TODO add your handling code here:
        System.exit(0);
    }//GEN-LAST:event_jMenuItemExitActionPerformed

    private void jMenuItemSerialDeviceConfigurationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemSerialDeviceConfigurationActionPerformed
        // TODO add your handling code here:
        ConfigSerialDialog cfgframe0 = new ConfigSerialDialog(this, true);
        cfgframe0.setTitle("Serial Device");
        cfgframe0.setConfig(programConfig.getSerialConfigDevice());
        cfgframe0.setVisible(true);
    }//GEN-LAST:event_jMenuItemSerialDeviceConfigurationActionPerformed

    private void jMenuItemSerialDebugConfigurationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemSerialDebugConfigurationActionPerformed
        // TODO add your handling code here:
        ConfigSerialDialog cfgframe1 = new ConfigSerialDialog(this, true);
        cfgframe1.setTitle("Serial Debug");
        cfgframe1.setConfig(programConfig.getSerialConfigDebug());
        cfgframe1.setVisible(true);
    }//GEN-LAST:event_jMenuItemSerialDebugConfigurationActionPerformed

    private void jButtonStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonStartActionPerformed
        // TODO add your handling code here:
        program.sendCommand("Me manda alguma coisa!");
        //jTextAreaLog.setText("");
        jTextAreaLog.append(program.receiveResponse()+"\n");
    }//GEN-LAST:event_jButtonStartActionPerformed

    private void jCheckBoxMenuItemOperationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxMenuItemOperationActionPerformed
        // TODO add your handling code here:
        if(jCheckBoxMenuItemOperation.getState()){
            jInternalFrameConfig.setVisible(true);
        }else{
            jInternalFrameConfig.setVisible(false);
        }
    }//GEN-LAST:event_jCheckBoxMenuItemOperationActionPerformed

    private void jCheckBoxMenuItemStatusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxMenuItemStatusActionPerformed
        // TODO add your handling code here:
        if(jCheckBoxMenuItemStatus.getState()){
            jInternalFrameStatus.setVisible(true);
        }else{
            jInternalFrameStatus.setVisible(false);
        }
    }//GEN-LAST:event_jCheckBoxMenuItemStatusActionPerformed

    private void jButtonConnectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonConnectActionPerformed
        // TODO add your handling code here:
        if (program.getDeviceConnected()) {
            program.disconnectDevice();
            jButtonConnect.setIcon(new ImageIcon(getClass().getResource("/Interface/icons/connect.png")));
            jButtonConnect.setToolTipText("Connect device");
        } else {
            if (program.connectDevice()) {
                jButtonConnect.setIcon(new ImageIcon(getClass().getResource("/Interface/icons/disconnect.png")));
                jButtonConnect.setToolTipText("Disconnect device");
            }
        }
    }//GEN-LAST:event_jButtonConnectActionPerformed

    private void jCheckBoxMenuItemOperationToolBarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxMenuItemOperationToolBarActionPerformed
        // TODO add your handling code here:
        if(jCheckBoxMenuItemOperationToolBar.getState()){
            jToolBarOperation.setVisible(true);
        }else{
            jToolBarOperation.setVisible(false);
        }
    }//GEN-LAST:event_jCheckBoxMenuItemOperationToolBarActionPerformed

    private void jCheckBoxMenuItemDeviceToolActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxMenuItemDeviceToolActionPerformed
        // TODO add your handling code here:
        if(jCheckBoxMenuItemDeviceTool.getState()){
            jToolBarDevice.setVisible(true);
        }else{
            jToolBarDevice.setVisible(false);
        }
    }//GEN-LAST:event_jCheckBoxMenuItemDeviceToolActionPerformed

    private void jInternalFrameConfigInternalFrameClosing(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_jInternalFrameConfigInternalFrameClosing
        // TODO add your handling code here:
        jCheckBoxMenuItemOperation.setSelected(false);
    }//GEN-LAST:event_jInternalFrameConfigInternalFrameClosing

    private void jInternalFrameStatusInternalFrameClosing(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_jInternalFrameStatusInternalFrameClosing
        // TODO add your handling code here:
        jCheckBoxMenuItemStatus.setSelected(false);
    }//GEN-LAST:event_jInternalFrameStatusInternalFrameClosing

    private void jButtonDebugActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonDebugActionPerformed
        // TODO add your handling code here:
        if (program.getDebugConnected()) {
            program.disconnectDebug();
            jButtonConnect.setIcon(new ImageIcon(getClass().getResource("/Interface/icons/connect.png")));
            jButtonConnect.setToolTipText("Connect device");
        } else {
            if (program.connectDevice()) {
                jButtonConnect.setIcon(new ImageIcon(getClass().getResource("/Interface/icons/disconnect.png")));
                jButtonConnect.setToolTipText("Disconnect device");
            }
        }
    }//GEN-LAST:event_jButtonDebugActionPerformed

    private void jCheckBoxMenuItemDebugActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxMenuItemDebugActionPerformed
        // TODO add your handling code here:
        if(jCheckBoxMenuItemDebug.getState()){
            jInternalFrameDebug.setVisible(true);
        }else{
            jInternalFrameDebug.setVisible(false);
        }
    }//GEN-LAST:event_jCheckBoxMenuItemDebugActionPerformed

    private void jInternalFrameDebugInternalFrameClosing(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_jInternalFrameDebugInternalFrameClosing
        // TODO add your handling code here:
        jCheckBoxMenuItemDebug.setSelected(false);
    }//GEN-LAST:event_jInternalFrameDebugInternalFrameClosing

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                     UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                } catch (UnsupportedLookAndFeelException ex) {
                     ex.printStackTrace();
                } catch (IllegalAccessException ex) {
                     ex.printStackTrace();
                } catch (InstantiationException ex) {
                     ex.printStackTrace();
                } catch (ClassNotFoundException ex) {
                     ex.printStackTrace();
                }

                new MainWindow().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonConfigDebug;
    private javax.swing.JButton jButtonConfigSerial;
    private javax.swing.JButton jButtonConnect;
    private javax.swing.JButton jButtonDebug;
    private javax.swing.JButton jButtonRestart;
    private javax.swing.JButton jButtonSend;
    private javax.swing.JButton jButtonStart;
    private javax.swing.JCheckBoxMenuItem jCheckBoxMenuItemDebug;
    private javax.swing.JCheckBoxMenuItem jCheckBoxMenuItemDeviceTool;
    private javax.swing.JCheckBoxMenuItem jCheckBoxMenuItemOperation;
    private javax.swing.JCheckBoxMenuItem jCheckBoxMenuItemOperationToolBar;
    private javax.swing.JCheckBoxMenuItem jCheckBoxMenuItemStatus;
    private javax.swing.JDesktopPane jDesktopPane;
    private javax.swing.JInternalFrame jInternalFrameConfig;
    private javax.swing.JInternalFrame jInternalFrameDebug;
    private javax.swing.JInternalFrame jInternalFrameStatus;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabelCommand;
    private javax.swing.JLabel jLabelCyclesStatus;
    private javax.swing.JLabel jLabelReport;
    private javax.swing.JLabel jLabelStepperSpeed;
    private javax.swing.JLabel jLabelStrain;
    private javax.swing.JLabel jLabelTime;
    private javax.swing.JLabel jLabelTimeout;
    private javax.swing.JLabel jLabelWireStep;
    private javax.swing.JLabel jLabelcycles;
    private javax.swing.JMenuBar jMenuBar;
    private javax.swing.JMenu jMenuConfiguration;
    private javax.swing.JMenu jMenuDevice;
    private javax.swing.JMenu jMenuFile;
    private javax.swing.JMenu jMenuHelp;
    private javax.swing.JMenuItem jMenuItemConnect;
    private javax.swing.JMenuItem jMenuItemConnectDebug;
    private javax.swing.JMenuItem jMenuItemExit;
    private javax.swing.JMenuItem jMenuItemOptions;
    private javax.swing.JMenuItem jMenuItemPause;
    private javax.swing.JMenuItem jMenuItemRestart;
    private javax.swing.JMenuItem jMenuItemSerialDebugConfiguration;
    private javax.swing.JMenuItem jMenuItemSerialDeviceConfiguration;
    private javax.swing.JMenuItem jMenuItemStart;
    private javax.swing.JMenu jMenuOperation;
    private javax.swing.JMenu jMenuToolBars;
    private javax.swing.JMenu jMenuView;
    private javax.swing.JPanel jPanelToolBar;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSpinner jSpinnerCycles;
    private javax.swing.JSpinner jSpinnerStepperSpeed;
    private javax.swing.JSpinner jSpinnerStraining;
    private javax.swing.JSpinner jSpinnerTimeout;
    private javax.swing.JSpinner jSpinnerWireStep;
    private javax.swing.JTextArea jTextAreaDebug;
    private javax.swing.JTextArea jTextAreaLog;
    private javax.swing.JTextField jTextFieldCommand;
    private javax.swing.JTextField jTextFieldCycles;
    private javax.swing.JTextField jTextFieldLength;
    private javax.swing.JTextField jTextFieldTime;
    private javax.swing.JToolBar jToolBarDevice;
    private javax.swing.JToolBar jToolBarOperation;
    // End of variables declaration//GEN-END:variables
    private Main program;
    private ParametersConfig programConfig;
    
}